package com.chaidb;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;

import com.db.DbConnection;

public class ShareMarker {
	@SuppressWarnings({ "finally", "unchecked","unused" })
	public HashMap doShareMarker(String markerid,String userid)
	{
		HashMap result;
		result = new HashMap();
		String state = null;
		System.out.println("I am here in share marker");
		String querysql = "select * from marker_share where mid='" +
			markerid + "' && uid='" + userid  + "';";
		System.out.println(querysql);
		String createsql = "insert into marker_share(mid,uid)values('" +
				markerid + "','" + userid  + "');";
		System.out.println(createsql);
			
		ShowAllShareMarkers db = new ShowAllShareMarkers();
		ArrayList markers = null;
		Connection con = null;
		try {
			con = DbConnection.getInstance().getConnection();
			Statement st = con.createStatement();
			ResultSet rs1 = st.executeQuery(querysql);
			if(rs1.next())
				state = "exist";
			else
			{
				Statement st2 = con.createStatement();
				int rs = st2.executeUpdate(createsql);
				state = "successful";
			}
			
			markers = db.doShowAllShareMarkers(userid);
		}catch(SQLException e)
		{
			e.printStackTrace();
		}finally
		{
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			result.put("state", state);
			result.put("markers", markers);
			return result;
		}
		
	}

}
